using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CM_KrisPianoAnimation : MonoBehaviour
{
	[Serializable]
	public class KeyPress
	{
		public int Key;

		public float TimeSinceLast;

		public KeyPress(int key, float timeSinceLast)
		{
			Key = key;
			TimeSinceLast = timeSinceLast;
		}
	}

	public List<KeyPress> keyPresses = new List<KeyPress>();

	public List<KeyPress> DWkeyPresses = new List<KeyPress>();

	private float lastPressTime;

	private PlayerManager Kris;

	public bool IsDarkworldVarient;

	private void Start()
	{
		Kris = PlayerManager.Instance;
	}

	private void Update()
	{
		if (DRHDebugManager.instance.DebugModeEnabled)
		{
			if (Input.GetKeyDown((KeyCode)49))
			{
				RecordKey(1);
			}
			else if (Input.GetKeyDown((KeyCode)50))
			{
				RecordKey(2);
			}
			else if (Input.GetKeyDown((KeyCode)51))
			{
				RecordKey(3);
			}
			else if (Input.GetKeyDown((KeyCode)52))
			{
				RecordKey(4);
			}
			if (Input.GetKeyDown((KeyCode)32))
			{
				((MonoBehaviour)this).StartCoroutine(Playback());
			}
		}
	}

	public void PlayRecording()
	{
		((MonoBehaviour)this).StartCoroutine(Playback());
		((MonoBehaviour)this).StartCoroutine(DWPlayback());
	}

	private void RecordKey(int key)
	{
		float time = Time.time;
		float num;
		if (IsDarkworldVarient)
		{
			num = ((DWkeyPresses.Count == 0) ? 0f : (time - lastPressTime));
			lastPressTime = time;
			DWkeyPresses.Add(new KeyPress(key, num));
		}
		else
		{
			num = ((keyPresses.Count == 0) ? 0f : (time - lastPressTime));
			lastPressTime = time;
			keyPresses.Add(new KeyPress(key, num));
		}
		Debug.Log((object)$"Recorded key {key} with time since last: {num}");
	}

	private IEnumerator Playback()
	{
		Debug.Log((object)"Starting playback...");
		foreach (KeyPress keyPress in keyPresses)
		{
			yield return (object)new WaitForSeconds(keyPress.TimeSinceLast);
			Kris._PMove._anim.Play($"Kris_CM_LWPianoNote{keyPress.Key}");
			Debug.Log((object)$"Key: {keyPress.Key}");
		}
		Debug.Log((object)"Playback finished.");
	}

	private IEnumerator DWPlayback()
	{
		foreach (KeyPress keyPress in DWkeyPresses)
		{
			yield return (object)new WaitForSeconds(keyPress.TimeSinceLast);
			if (IsDarkworldVarient)
			{
				Kris._PMove._anim.Play($"Kris_CM_DWPianoNote{keyPress.Key}");
			}
			Debug.Log((object)$"Key: {keyPress.Key}");
		}
	}
}
